package com.csx.saas.platform.auth.grant;

import com.csx.basic.jwt.TokenUtil;
import com.csx.basic.jwt.model.AuthInfo;
import com.csx.basic.jwt.model.JwtUserInfo;
import com.csx.saas.platform.system.entity.SystemUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * token 抽象类
 *
 * @author ChenSongXin
 * @date 2021/2/19 17:04
 */
@Slf4j
@RequiredArgsConstructor
public abstract class AbstractTokenGranter {
    @Autowired
    private TokenUtil tokenUtil;

    /**
     * 创建用户TOKEN
     *
     * @param systemUser 用户
     * @return token
     */
    protected AuthInfo createToken(SystemUser systemUser) {
        JwtUserInfo userInfo = new JwtUserInfo(systemUser.getId(), systemUser.getAccount(), systemUser.getName());
        AuthInfo authInfo = tokenUtil.createAuthInfo(userInfo, null);
        authInfo.setAvatar(systemUser.getAvatar());
        authInfo.setWorkDescribe(systemUser.getDescribe());
        return authInfo;
    }
}
